import routeDefine from './route-define.js';
import store from '@/store';

export default {
  install(Vue) {
    routeDefine.forEach((item) => {
      Vue.component(item.name, item.component);
    });
    Vue.prototype.$tab = {
      query() {
        return store.getters.__getTabQuery;
      },
      add(item) {
        store.commit('__addTab', item);
      },
      push(target) {
        const data = {};
        if (typeof target === 'string') {
          data.name = target;
        } else {
          data.name = target.name;
          data.query = target.query || {};
        }
        store.commit('__pushTab', data);
      },
      remove(flag) {
        store.commit('__removeTab', flag);
      },
      back(n = 1) {
        store.commit('__backTab', n);
      },
    };
  },
};
